Skip to content

Unique Paths ​

Unique Paths — LeetCode

A robot starts at the top-left of an m x n grid and can only move right or down. Count the number of distinct paths to the bottom-right corner.

Approach ​

It can only go right or down. So a 2D DP with recursion (result of going down + going left) and memoization will solve. Optimization: 1-DP, go from bottom to top, right to left. The rightmost value is always 1. Then each value is b[j] = b[j] + b[j+1].

A binomial coefficient can also solve this.

Remarks ​

Pasted image 20260712013209.png